import { Module, VuexModule, Mutation, getModule } from 'vuex-module-decorators';
import store from '@/store';

@Module({ name: 'user', namespaced: true, dynamic: true, store })
export default class UserStore extends VuexModule {
    public sessid: string = uni.getStorageSync('sessid') || '';
    public userInfo: any = uni.getSystemInfoSync();
    // 设置系统参数
    @Mutation
    public login(): void {
        uni.setStorageSync('sessid', '123456')
        uni.switchTab({
            url: '/pages/home/index'
        })
    }

    @Mutation
    public isLogin(): void {
        if (this.sessid) {
            uni.switchTab({
                url: '/pages/home/index'
            })
        }
    }

    @Mutation
    public LoginOut(): void {
        uni.removeStorageSync('sessid');
        uni.navigateTo({
            url: "/pages/login/index",
        });
    }
}

export const UserModule = getModule(UserStore);
